package se.jocke.nb.proxy.monitor.service.impl;

import java.util.prefs.Preferences;
import org.openide.util.NbPreferences;
import org.openide.util.lookup.ServiceProvider;
import se.jocke.nb.proxy.monitor.service.ProxySettings;
import se.jocke.nb.proxy.monitor.service.ProxySettingsManager;

@ServiceProvider(service = ProxySettingsManager.class)
public class ProxySettingsManagerImpl implements ProxySettingsManager {

    private static final Preferences PREFERENCES = NbPreferences.forModule(ProxySettingsManagerImpl.class);

    public static final String PROXY_TO_HOST = "proxyToHost";

    public static final String PROXY_TO_PORT = "proxyToPort";

    public static final String PROXY_PORT = "proxyPort";

    @Override
    public ProxySettings getProxySettings() {
        int proxyPort = PREFERENCES.getInt(PROXY_PORT, 48080);
        int proxyToPort = PREFERENCES.getInt(PROXY_TO_PORT, 8080);
        String proxyToHost = PREFERENCES.get(PROXY_TO_HOST, "localhost");
        return new ProxySettings(proxyPort, proxyToPort, proxyToHost);
    }

    @Override
    public void saveProxySettings(ProxySettings settings) {
        PREFERENCES.putInt(PROXY_PORT, settings.getProxyPort());
        PREFERENCES.putInt(PROXY_TO_PORT, settings.getProxyToPort());
        PREFERENCES.put(PROXY_TO_HOST, settings.getProxyToHost());
    }

}
